<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>hello world</title>
</head>
<body>
    <div id="app">
        <div>
            <!-- 4、<router-link>默认会被渲染成一个 `<a>` 标签 ,to指令跳转到指定路径 -->
            <router-link to="/home">Go to Home</router-link>
            <router-link to="/about">Go to About</router-link>
        </div>

        <!-- 5、在页面上使用<router-view></router-view>标签，用于渲染匹配的组件 -->
        <router-view></router-view>            
    </div>

    <!-- 0、引入依赖库 -->
    <script src="../js/vue.min.js"></script>
    <script src="https://unpkg.com/vue-router"></script>

    <script type="text/javascript">
        /* 1、创建组件 */
        const Home = Vue.extend({
            template: '<div><h1>Home</h1><p>{{msg}}</p></div>',
            data: function() {
                return {
                    msg: 'Hello, vue router!'
                }
            }
        });
        const About = Vue.extend({
            template: '<div><h1>About</h1><p>This is the tutorial about vue-router.</p></div>'
        });

        // 2. 创建 router 实例，然后传 `routes`路由映射 配置
        const router = new VueRouter({
          routes: [
            { path: '/home', component: Home },
              { path: '/about', component: About },
              { path: '/', component: Home } //设置默认路径
          ] 
        });

        // 3. 创建和挂载根实例。记得要通过 router 配置参数注入路由，从而让整个应用都有路由功能
        const vm = new Vue({
              router: router 
        }).$mount('#app');

        // 现在，应用已经启动了！
    </script>
</body>
</html>